package edu.towson.greenteam.tab;

import java.util.ArrayList;
import edu.towson.greenteam.Collection;
import edu.towson.greenteam.Iterator;

public class Tabs implements Collection<Tab> {
	
	public ArrayList<Tab> currentTabs;
	
	public Tabs() {		
		currentTabs = new ArrayList<Tab>();
	}
	
	@Override
	public boolean add(Tab e) {
		return currentTabs.add(e);
	}
	
	public boolean add(int id) {
		Tab e = new Tab(id);
		return currentTabs.add(e);
	}
	
	@Override
	public boolean update(Tab e) {
		TabAllItr tabItr = new TabAllItr(this);
		while (tabItr.hasNext()) {
			Tab foundTab = tabItr.next();
			if (foundTab == e) {
				currentTabs.remove(currentTabs.indexOf(foundTab));
				currentTabs.add(e);
				return true;
			}
		}
		return false;
	}
	
	@Override
	public boolean contains(Tab e) {
		return currentTabs.contains(e);
	}
	
	@Override
	public boolean remove(Tab e) {
		return currentTabs.remove(e);
	}
	
	@Override
	public boolean isEmpty() {
		return currentTabs.isEmpty();
	}
	
	@Override
	public int size() {
		return currentTabs.size();
	}
	
	public Iterator<Tab> createTabAllItr(Tabs allTabs) {
		return new TabAllItr(allTabs);
	}

	public Tab get(int i) {
		//check to make sure i is less than size
		if (currentTabs.size() > i) {
			return currentTabs.get(i);
		}
		else {
			return null;
		}
	}
}
